from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-12 14:04:11.769148
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 12, Jan, 2022
Time: 14:04:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6815
Nobs: 534.000 HQIC: -48.1207
Log likelihood: 6194.17 FPE: 9.52550e-22
AIC: -48.4029 Det(Omega_mle): 8.06063e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.385046 0.071899 5.355 0.000
L1.Burgenland 0.100005 0.042915 2.330 0.020
L1.Kärnten -0.113229 0.022153 -5.111 0.000
L1.Niederösterreich 0.186027 0.089178 2.086 0.037
L1.Oberösterreich 0.113293 0.088743 1.277 0.202
L1.Salzburg 0.268436 0.045318 5.923 0.000
L1.Steiermark 0.024258 0.059737 0.406 0.685
L1.Tirol 0.108439 0.048151 2.252 0.024
L1.Vorarlberg -0.077110 0.042552 -1.812 0.070
L1.Wien 0.010943 0.078507 0.139 0.889
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058573 0.157572 0.372 0.710
L1.Burgenland -0.042263 0.094052 -0.449 0.653
L1.Kärnten 0.039909 0.048550 0.822 0.411
L1.Niederösterreich -0.207021 0.195440 -1.059 0.289
L1.Oberösterreich 0.455421 0.194488 2.342 0.019
L1.Salzburg 0.286144 0.099318 2.881 0.004
L1.Steiermark 0.113852 0.130918 0.870 0.384
L1.Tirol 0.306930 0.105526 2.909 0.004
L1.Vorarlberg 0.020156 0.093257 0.216 0.829
L1.Wien -0.022477 0.172053 -0.131 0.896
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199644 0.036792 5.426 0.000
L1.Burgenland 0.091244 0.021961 4.155 0.000
L1.Kärnten -0.007734 0.011336 -0.682 0.495
L1.Niederösterreich 0.232389 0.045634 5.092 0.000
L1.Oberösterreich 0.166387 0.045412 3.664 0.000
L1.Salzburg 0.040564 0.023190 1.749 0.080
L1.Steiermark 0.024587 0.030569 0.804 0.421
L1.Tirol 0.082754 0.024640 3.359 0.001
L1.Vorarlberg 0.054385 0.021775 2.498 0.013
L1.Wien 0.117282 0.040174 2.919 0.004
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127453 0.036762 3.467 0.001
L1.Burgenland 0.040841 0.021943 1.861 0.063
L1.Kärnten -0.014355 0.011327 -1.267 0.205
L1.Niederösterreich 0.169472 0.045597 3.717 0.000
L1.Oberösterreich 0.333980 0.045375 7.360 0.000
L1.Salzburg 0.104928 0.023171 4.528 0.000
L1.Steiermark 0.109125 0.030544 3.573 0.000
L1.Tirol 0.092209 0.024620 3.745 0.000
L1.Vorarlberg 0.055423 0.021757 2.547 0.011
L1.Wien -0.019670 0.040141 -0.490 0.624
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107159 0.069830 1.535 0.125
L1.Burgenland -0.041151 0.041681 -0.987 0.324
L1.Kärnten -0.046164 0.021516 -2.146 0.032
L1.Niederösterreich 0.142439 0.086612 1.645 0.100
L1.Oberösterreich 0.170815 0.086190 1.982 0.047
L1.Salzburg 0.281007 0.044014 6.384 0.000
L1.Steiermark 0.063352 0.058018 1.092 0.275
L1.Tirol 0.155693 0.046766 3.329 0.001
L1.Vorarlberg 0.094633 0.041328 2.290 0.022
L1.Wien 0.076194 0.076248 0.999 0.318
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.094719 0.054237 1.746 0.081
L1.Burgenland 0.019611 0.032373 0.606 0.545
L1.Kärnten 0.052150 0.016711 3.121 0.002
L1.Niederösterreich 0.188992 0.067271 2.809 0.005
L1.Oberösterreich 0.325718 0.066944 4.866 0.000
L1.Salzburg 0.039748 0.034186 1.163 0.245
L1.Steiermark -0.004390 0.045063 -0.097 0.922
L1.Tirol 0.125649 0.036323 3.459 0.001
L1.Vorarlberg 0.063995 0.032100 1.994 0.046
L1.Wien 0.094996 0.059222 1.604 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164876 0.065735 2.508 0.012
L1.Burgenland 0.009381 0.039236 0.239 0.811
L1.Kärnten -0.065974 0.020254 -3.257 0.001
L1.Niederösterreich -0.112931 0.081533 -1.385 0.166
L1.Oberösterreich 0.219205 0.081136 2.702 0.007
L1.Salzburg 0.051305 0.041433 1.238 0.216
L1.Steiermark 0.253087 0.054616 4.634 0.000
L1.Tirol 0.499506 0.044023 11.346 0.000
L1.Vorarlberg 0.065437 0.038905 1.682 0.093
L1.Wien -0.079976 0.071777 -1.114 0.265
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169825 0.072743 2.335 0.020
L1.Burgenland -0.009043 0.043419 -0.208 0.835
L1.Kärnten 0.062936 0.022413 2.808 0.005
L1.Niederösterreich 0.173966 0.090224 1.928 0.054
L1.Oberösterreich -0.065505 0.089785 -0.730 0.466
L1.Salzburg 0.207834 0.045850 4.533 0.000
L1.Steiermark 0.135977 0.060438 2.250 0.024
L1.Tirol 0.055212 0.048716 1.133 0.257
L1.Vorarlberg 0.143855 0.043052 3.341 0.001
L1.Wien 0.127787 0.079428 1.609 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.403484 0.042447 9.506 0.000
L1.Burgenland -0.004411 0.025336 -0.174 0.862
L1.Kärnten -0.020565 0.013078 -1.572 0.116
L1.Niederösterreich 0.201055 0.052647 3.819 0.000
L1.Oberösterreich 0.238904 0.052391 4.560 0.000
L1.Salzburg 0.036329 0.026754 1.358 0.175
L1.Steiermark -0.019876 0.035267 -0.564 0.573
L1.Tirol 0.088388 0.028427 3.109 0.002
L1.Vorarlberg 0.050297 0.025122 2.002 0.045
L1.Wien 0.029861 0.046348 0.644 0.519
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033240 0.094321 0.159379 0.136204 0.082208 0.078974 0.024511 0.204577
Kärnten 0.033240 1.000000 -0.027805 0.132519 0.047469 0.083194 0.447411 -0.071071 0.093423
Niederösterreich 0.094321 -0.027805 1.000000 0.305565 0.124158 0.261013 0.063669 0.154824 0.276381
Oberösterreich 0.159379 0.132519 0.305565 1.000000 0.216194 0.290771 0.166961 0.130746 0.229271
Salzburg 0.136204 0.047469 0.124158 0.216194 1.000000 0.124981 0.081783 0.108355 0.126217
Steiermark 0.082208 0.083194 0.261013 0.290771 0.124981 1.000000 0.133508 0.101319 0.022522
Tirol 0.078974 0.447411 0.063669 0.166961 0.081783 0.133508 1.000000 0.064182 0.146573
Vorarlberg 0.024511 -0.071071 0.154824 0.130746 0.108355 0.101319 0.064182 1.000000 -0.009370
Wien 0.204577 0.093423 0.276381 0.229271 0.126217 0.022522 0.146573 -0.009370 1.000000